import { Adventure } from '@/business/adventure/entities/adventure.entity';
import { User } from '@/business/user/entities/user.entity';
import { CommonEntity } from '@/common/common-entity';
import { ApiPropertyOptional } from '@nestjs/swagger';
import { Column, Entity, ManyToOne } from 'typeorm';

@Entity()
export class Task extends CommonEntity {
  @ApiPropertyOptional({ description: '任务名称' })
  @Column({
    type: 'varchar',
    nullable: false,
    unique: true,
    comment: '任务名称'
  })
  name: string;

  @ApiPropertyOptional({ description: '任务等级' })
  @Column({
    type: 'int',
    comment: '任务等级',
    nullable: false,
    default: 1
  })
  level: number;
  @ApiPropertyOptional({
    description: '任务类型, 探索-1,赏金-2,挑战-3,收集-4,护送-5'
  })
  @Column({
    type: 'tinyint',
    comment: '任务类型, 探索-1,赏金-2,挑战-3,收集-4,护送-5',
    nullable: true
  })
  type: number;
  @ApiPropertyOptional({ description: '任务状态,未完成-1,已完成-2,进行中-3' })
  @Column({
    type: 'tinyint',
    comment: '任务状态,未完成-1,已完成-2,进行中-3',
    nullable: false,
    default: 1
  })
  status: number;

  @ApiPropertyOptional({ description: '任务描述' })
  @Column({
    type: 'varchar',
    comment: '任务描述'
  })
  desc: string;

  // 任务 多对一 冒险者
  @ManyToOne(()=> Adventure, (adventure)=> adventure.tasks,{
    cascade: ['insert','update']  // 当对主题执行操作时，自动对关联的对象也执行相同操作
  })
  adventure: Adventure


  // 任务 多对一 用户
  @ManyToOne(()=> User, (user)=>user.tasks )
  publisher: User
}
